Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bugs in translation of PM_RESCUE_NODE #317

Merged
merged 5 commits into from
Nov 5, 2024
Merged

Fix bugs in translation of PM_RESCUE_NODE #317

merged 5 commits into from
Nov 5, 2024

Conversation

egiurleo
Copy link

@egiurleo egiurleo commented Nov 1, 2024

Related to #316

Motivation

Easiest to read each commit separately.

This PR addresses some issues with PM_RESCUE_NODE:

  1. First, we were relying on the body of the begin node within the rescue to determine the location. It is entirely possible that the rescue will not have a body.
  2. We were doing the dynamic constant assignment workaround for all the node types that passed through translateConst, rather than just the ones that actually handle constant assignment.
  3. We weren't testing the dynamic constant assignment workaround with all the different types of constant assignment.

Test plan

See included automated tests.

@egiurleo egiurleo self-assigned this Nov 1, 2024
@egiurleo egiurleo changed the title Fix two small bugs in translation of PM_RESCUE_NODE Fix bugs in translation of PM_RESCUE_NODE Nov 1, 2024
Copy link
Member

@st0012 st0012 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a blocker, but maybe we can also test these cases?

begin
rescue Foo => e
end

begin
  "something"
rescue Foo => e
end

@egiurleo egiurleo force-pushed the emily/rescue branch 2 times, most recently from 2cdea4e to c24cdd7 Compare November 4, 2024 16:37
parser/prism/Translator.cc Outdated Show resolved Hide resolved
Copy link

@amomchilov amomchilov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really interesting find, great work

parser/prism/Translator.h Show resolved Hide resolved
parser/prism/Translator.cc Outdated Show resolved Hide resolved
@@ -1639,7 +1641,7 @@ unique_ptr<parser::Node> Translator::translateStatements(pm_statements_node *stm
// Usually returns the `SorbetLHSNode`, but for constant writes and targets,
// it can can return an `LVarLhs` as a workaround in the case of a dynamic constant assignment.
template <typename PrismLhsNode, typename SorbetLHSNode>
unique_ptr<parser::Node> Translator::translateConst(PrismLhsNode *node) {
unique_ptr<parser::Node> Translator::translateConst(PrismLhsNode *node, bool skipDynamicConstantWorkaround) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a blurb to the function docs that explains what this is (and why constant path op assignments need it)?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@amomchilov Let me know what you think of the explanation above!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@egiurleo egiurleo force-pushed the emily/rescue branch 2 times, most recently from 7f71bc9 to 576c29c Compare November 5, 2024 21:50
@egiurleo egiurleo merged commit 5b7a69f into prism Nov 5, 2024
1 check passed
@egiurleo egiurleo deleted the emily/rescue branch November 5, 2024 22:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants